﻿using BasicInformation.ApiRead.Application.Command.Supplier;
using BasicInformation.Domain;
using BasicInformation.ErrorCode;
using BasicInformation.Infrastructure.Implement;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.ApiRead.Application.Handler.Supplier
{
    public class GetSupplierTypeHandler : IRequestHandler<GetSupplierTypeCommand, ApiPaging<SupplierTypeModel>>
    {
        private readonly IBaseRepository<SupplierTypeModel> supplierTypeRepo;
        private readonly DatabaseContext db;
        private readonly ILogger<GetSupplierTypeHandler> logger;

        public GetSupplierTypeHandler(DatabaseContext db, ILogger<GetSupplierTypeHandler> logger)
        {
            this.supplierTypeRepo = supplierTypeRepo;
            this.db = db;
            this.logger = logger;
        }
        public Task<ApiPaging<SupplierTypeModel>> Handle(GetSupplierTypeCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<SupplierTypeModel> result = new ApiPaging<SupplierTypeModel>();
            var sql = @"SELECT a.STypeId,a.STypeName FROM suppliertypemodel as a WHERE 1=1";
            var re = db.SqlSugar.Queryable<SupplierTypeModel>();
            result.Data = re.ToList();
            result.Code = ApiEnum.OK;
            result.Msg = "供应商类型查询成功";
            logger.LogInformation(result.Msg);
            return Task.FromResult(result);
        }
    }
}
